package com.sen.gulimall.ware.exception;

import com.sen.common.exception.BizCodeEnum;
import com.sen.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName: GulimallExceptionControllerAdvice
 * @Title: gulimall
 * @Package: com.sen.gulimall.ware.exception
 * @Description:
 * @Author: Kisen
 * @Date: 2022/3/13 16:27
 */
@Slf4j
@RestControllerAdvice
public class GulimallExceptionControllerAdvice {

    @ExceptionHandler(value = RuntimeException.class)
    public R handleRuntimeException(RuntimeException e) {
        log.error("运行时异常{}", e);
        return R.error(BizCodeEnum.RUNTIME_EXCEPTION.getCode(), e.getMessage());
    }

    @ExceptionHandler(value = Throwable.class)
    public R handleException(Throwable throwable) {
        log.error("系统异常{}", throwable);
        return R.error(BizCodeEnum.UNKOWN_EXCEPTION.getCode(), BizCodeEnum.UNKOWN_EXCEPTION.getMsg());
    }
}
